package mock_seed

import (
	"time"
	"wms/internal/model"
	"wms/pkg/database"
	"wms/pkg/logger"

	"go.uber.org/zap"
)

// InitFrozenFoodCustomers 初始化冷链食品客户数据
func InitFrozenFoodCustomers() error {
	logger.Info("开始初始化冷链食品客户数据...")
	db := database.GetDB()

	// 清空现有客户数据
	if err := db.Exec("DELETE FROM customers").Error; err != nil {
		logger.Error("清空客户数据失败", zap.Error(err))
		return err
	}

	// 冷链食品客户列表
	customers := []model.Customer{
		{
			Code:      "CUS001",
			Name:      "北京星级餐饮集团有限公司",
			Contact:   "张经理",
			Phone:     "13800138001",
			Email:     "purchasing@bjstar.com",
			Address:   "北京市朝阳区建国路100号星级商务中心",
			Status:    1,
			TaxNumber: "91110105MA00F4XL2B",
			Bank:      "中国工商银行北京朝阳支行",
			Account:   "6212260200012345678",
			Level:     3,
			Credit:    1,
			Remark:    "五星级连锁酒店集团，对冷冻肉类和海鲜需求量大，要求品质高",
		},
		{
			Code:      "CUS002",
			Name:      "上海大润发超市连锁有限公司",
			Contact:   "李采购",
			Phone:     "13900139002",
			Email:     "purchase@rt-mart.com.cn",
			Address:   "上海市浦东新区张江高科技园区春晓路699号",
			Status:    1,
			TaxNumber: "913101150878765432",
			Bank:      "中国建设银行上海浦东支行",
			Account:   "6227001215632145698",
			Level:     3,
			Credit:    1,
			Remark:    "大型连锁超市，冷冻食品销售渠道广，每周固定采购",
		},
		{
			Code:      "CUS003",
			Name:      "广州餐饮配送服务有限公司",
			Contact:   "王总监",
			Phone:     "13700137003",
			Email:     "service@gzfoodservice.com",
			Address:   "广州市天河区珠江新城冼村路12号",
			Status:    1,
			TaxNumber: "91440106MA9ABCDEF0",
			Bank:      "中国银行广州天河支行",
			Account:   "6228480038009123456",
			Level:     2,
			Credit:    1,
			Remark:    "专业餐饮配送企业，服务珠三角地区众多餐厅，冷链配送能力强",
		},
		{
			Code:      "CUS004",
			Name:      "成都川派火锅原料有限公司",
			Contact:   "赵经理",
			Phone:     "15600156004",
			Email:     "info@cdhotpot.com",
			Address:   "成都市武侯区科华北路65号",
			Status:    1,
			TaxNumber: "915101073456789012",
			Bank:      "招商银行成都科华支行",
			Account:   "6225880123456789",
			Level:     2,
			Credit:    1,
			Remark:    "四川火锅食材批发商，对冷冻肉片需求量特别大，要求新鲜度高",
		},
		{
			Code:      "CUS005",
			Name:      "重庆巴蜀餐饮管理有限公司",
			Contact:   "钱总",
			Phone:     "13500135005",
			Email:     "contact@cqfood.com",
			Address:   "重庆市江北区观音桥步行街18号",
			Status:    1,
			TaxNumber: "91500105ABCDEFG123",
			Bank:      "中国农业银行重庆江北支行",
			Account:   "6228481234567890123",
			Level:     2,
			Credit:    1,
			Remark:    "重庆本地餐饮连锁企业，30多家门店，需求稳定",
		},
		{
			Code:      "CUS006",
			Name:      "深圳海鲜楼饮食集团",
			Contact:   "孙经理",
			Phone:     "13600136006",
			Email:     "purchase@szseafood.com",
			Address:   "深圳市南山区科技园南区10栋",
			Status:    1,
			TaxNumber: "91440300HIJKLMN456",
			Bank:      "中国民生银行深圳分行",
			Account:   "6226220123456789",
			Level:     3,
			Credit:    1,
			Remark:    "高端海鲜餐厅连锁，对进口冷冻海鲜要求极高，是VIP客户",
		},
		{
			Code:      "CUS007",
			Name:      "杭州西湖餐饮管理有限公司",
			Contact:   "吴采购",
			Phone:     "13400134007",
			Email:     "purchase@hzxihu.com",
			Address:   "杭州市西湖区西溪路528号",
			Status:    1,
			TaxNumber: "91330106OPQRSTU789",
			Bank:      "中信银行杭州分行",
			Account:   "6221123456789012",
			Level:     2,
			Credit:    1,
			Remark:    "杭帮菜餐饮连锁企业，对冷冻鸡鸭鱼肉需求多样化",
		},
		{
			Code:      "CUS008",
			Name:      "青岛海鲜水产批发市场",
			Contact:   "周总",
			Phone:     "13300133008",
			Email:     "market@qdseafood.com",
			Address:   "青岛市崂山区崂山路88号",
			Status:    1,
			TaxNumber: "91370212VWXYZ12345",
			Bank:      "青岛银行总行营业部",
			Account:   "6223456789012345",
			Level:     2,
			Credit:    2,
			Remark:    "山东最大海产品批发市场，采购量大但账期较长",
		},
		{
			Code:      "CUS009",
			Name:      "沈阳东北菜餐饮有限公司",
			Contact:   "郑经理",
			Phone:     "13200132009",
			Email:     "info@synefood.com",
			Address:   "沈阳市和平区太原街256号",
			Status:    1,
			TaxNumber: "91210102ABCDEF1234",
			Bank:      "交通银行沈阳分行",
			Account:   "6222123456789101",
			Level:     1,
			Credit:    1,
			Remark:    "特色东北菜连锁，对冷冻肉类有严格的品质要求",
		},
		{
			Code:      "CUS010",
			Name:      "武汉学校食堂配送中心",
			Contact:   "马主任",
			Phone:     "13100131010",
			Email:     "supply@whschool.com",
			Address:   "武汉市洪山区珞瑜路205号",
			Status:    1,
			TaxNumber: "91420111GHIJKL5678",
			Bank:      "中国银行武汉分行",
			Account:   "6228901234567890",
			Level:     2,
			Credit:    1,
			Remark:    "为武汉市50多所学校提供食材配送，对冷冻食品安全要求极高",
		},
		{
			Code:      "CUS011",
			Name:      "西安饮食文化有限公司",
			Contact:   "柳总",
			Phone:     "13000130011",
			Email:     "contact@xafood.com",
			Address:   "西安市碑林区长安北路99号",
			Status:    1,
			TaxNumber: "91610103MNOPQR7890",
			Bank:      "陕西省农村信用社",
			Account:   "6227123456789012",
			Level:     1,
			Credit:    1,
			Remark:    "西北特色餐饮企业，对冷冻肉类需求稳定",
		},
		{
			Code:      "CUS012",
			Name:      "南宁市酒店用品有限公司",
			Contact:   "唐经理",
			Phone:     "13500135012",
			Email:     "sales@nnhotel.com",
			Address:   "南宁市青秀区民族大道156号",
			Status:    1,
			TaxNumber: "91450102STUVWX3456",
			Bank:      "广西壮族自治区农村信用社",
			Account:   "6228123456789012",
			Level:     1,
			Credit:    2,
			Remark:    "为广西地区酒店提供食材和用品，对冷冻海鲜需求较大",
		},
	}

	// 添加客户
	now := time.Now()
	for i, customer := range customers {
		customer.CreatedAt = now
		customer.UpdatedAt = now
		customer.ID = uint(i + 1) // 确保ID从1开始连续

		// 直接创建客户，不检查是否存在
		if err := db.Create(&customer).Error; err != nil {
			logger.Error("创建客户失败", zap.String("name", customer.Name), zap.Error(err))
			return err
		}
		logger.Info("创建客户成功", zap.String("name", customer.Name))
	}

	logger.Info("冷链食品客户数据初始化成功")
	return nil
}
